package com.example.demo.repository;

import com.example.demo.entity.CopyrightTradeRequestEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 版权交易请求仓库
 */
@Repository
public interface CopyrightTradeRequestRepository extends JpaRepository<CopyrightTradeRequestEntity, Long> {

    /**
     * 根据版权ID查找交易请求
     */
    List<CopyrightTradeRequestEntity> findByCopyrightId(Long copyrightId);
    
    /**
     * 查找用户发起的交易请求
     */
    List<CopyrightTradeRequestEntity> findByFromAddressOrderByCreateTimeDesc(String fromAddress);
    
    /**
     * 查找用户接收的交易请求
     */
    List<CopyrightTradeRequestEntity> findByToAddressOrderByCreateTimeDesc(String toAddress);
    
    /**
     * 查找用户接收的未处理交易请求
     */
    List<CopyrightTradeRequestEntity> findByToAddressAndStatusOrderByCreateTimeDesc(String toAddress, Integer status);

    /**
     * 根据发起方和接收方查找未处理的交易请求
     */
    List<CopyrightTradeRequestEntity> findByFromAddressAndToAddressAndStatusOrderByCreateTimeDesc(
            String fromAddress, String toAddress, Integer status);
    
    /**
     * 根据版权ID和接收方查找未处理的交易请求，按请求时间倒序排序
     * @param copyrightId 版权ID
     * @param toAddress 接收方地址
     * @param status 状态
     * @return 交易请求列表
     */
    List<CopyrightTradeRequestEntity> findByCopyrightIdAndToAddressAndStatusOrderByCreateTimeDesc(
            Long copyrightId, String toAddress, Integer status);
} 